home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / web / cweb.lha / cweb / cwebmac.tex < prev    next >
Text File  |  1990-07-13  |  11KB  |  244 lines

  1. % standard macros for WEB listings (in addition to PLAIN.TEX)
  2. % $Revision: 1.9 $
  3. % $Date: 89/10/12 18:41:24 $
  4. \let\amp=\&
  5. \parskip 0pt % no stretch between paragraphs
  6. \parindent 1em % for paragraphs and for the first line of C text
  7.  
  8. \font\eightrm=cmr8 % this will eventually become cmr8
  9. \let\sc=\eightrm \let\mainfont=\tenrm
  10. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  11. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  12. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  13.  
  14. \def\~{\char`\~}
  15. \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  16. \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
  17. \def\{\leavevmode\hbox{\bf#1\/}} % boldface type for reserved words
  18. \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
  19.   \let\\=\BS % backslash in a string
  20.   \let\'=\RQ % right quote in a string
  21.   \let\`=\LQ % left quote in a string
  22.   \let\{=\LB % left brace in a string
  23.   \let\}=\RB % right brace in a string
  24.   \let\~=\TL % tilde in a string
  25.   \let\ =\SP % space in a string
  26.   \let\_=\UL % underline in a string
  27.   \let\&=\AM % ampersand in a string
  28.   #1}}
  29. \def\nxt#1{\ifx#1\egroup#1\else#1\discretionary{\\}{}{}\expandafter\nxt\fi}
  30. \def\)#1{\leavevmode\bgroup\tentex % breakable typewriter type
  31.   \let\\=\BS % backslash in a string
  32.   \let\'=\RQ % right quote in a string
  33.   \let\`=\LQ % left quote in a string
  34.   \let\{=\LB % left brace in a string
  35.   \let\}=\RB % right brace in a string
  36.   \let\~=\TL % tilde in a string
  37.   \let\ =\SP % space in a string
  38.   \let\_=\UL % underline in a string
  39.   \let\&=\AM % ampersand in a string
  40.   \nxt#1\egroup}
  41. \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
  42. % circumflex accents can be obtained from \^^D instead of \^
  43. \def\AT{@} % at sign for control text
  44.  
  45. \chardef\AM=`\& % ampersand character in a string
  46. \chardef\BS=`\\ % backslash in a string
  47. \chardef\LB=`\{ % left brace in a string
  48. \def\LQ{{\tt\char'22}} % left quote in a string
  49. \chardef\RB=`\} % right brace in a string
  50. \def\RQ{{\tt\char'23}} % right quote in a string
  51. \def\SP{{\tt\char`\ }} % (visible) space in a string
  52. \chardef\TL=`\~ % tilde in a string
  53. \chardef\UL=`\_ % underline character in a string
  54.  
  55. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  56. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  57.  
  58. \newcount\ind % current indentation in ems
  59. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  60. \def\2{\global\advance\ind by-1} % indent one less notch
  61. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  62. \def\4{\copy\bak} % backspace one notch
  63. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  64. \def\6{\ifmmode\else\par % forced break
  65.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  66. \def\7{\Y\6} % forced break and a little extra space
  67. \def\8{\hskip-\ind em\hskip 2em} % no indentation
  68.  
  69. \let\yskip=\smallskip
  70. \def\?{\mathrel?}
  71. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1 #2.\par}}
  72. \def\lapstar{\rlap{*}}
  73. \def\startsection{\Q\noindent{\let\*=\lapstar\bf\modstar.\quad}}
  74. \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
  75. \def\A{\note{See also}} % cross-reference for multiply defined section names
  76. \def\B{\mathopen{\.{@/\ast}}} % begin controlled comment
  77. \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % C comments
  78.   \XX\hfil\penalty-1\hfilneg\quad$/\ast\,$#1$\,\ast/$\XX}
  79. \def\D{\defin{\#define} } % macro definition
  80. \def\F{\defin{format}} % format definition
  81. \let\G=\ge % greater than or equal sign
  82. \let\I=\ne % unequal sign
  83. \def\J{\.{@\&}} % TANGLE's join operation
  84. \let\K== % can be changed to left arrow, if desired
  85. \let\L=\le % less than or equal sign
  86. \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
  87.   \vskip12ptminus3pt\startsection\ignorespaces}
  88. \outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
  89.   \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
  90.   \message{*\modno} % progress report
  91.   \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file
  92.   \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
  93. \def\MN#1.{\par % common code for \M, \N
  94.   {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}
  95.   \ifx\modno\modstar \onmaybe \else\ontrue \fi \mark{\modno}}
  96. \def\O#1{% octal, hex or decimal constant
  97.   {\def\?{\kern.2em}%
  98.   \def\${\ell}% long constant
  99.   \def\_{\cdot 10^{\aftergroup}}% power of ten
  100.   \def\~{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}}% octal
  101.   \def\^{\hbox{\rm\char"7D\tt\aftergroup}}#1}}% double quotes for hex constant
  102. \def\P{\rightskip=0pt plus 100pt minus 10pt % go into C mode
  103.   \sfcode`;=3000
  104.   \pretolerance 10000
  105.   \hyphenpenalty 9999 % so strings can be broken (a discretionary \ is inserted)
  106.   \exhyphenpenalty 10000
  107.   \global\ind=2 \1\ \unskip}
  108. \def\Q{\rightskip=0pt % get out of C mode
  109.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
  110. \let\R=\lnot % logical not
  111. \let\S=\equiv % equivalence sign
  112. \def\T{\mathclose{\.{@\ast/}}} % terminate controlled comment
  113. \def\U{\note{This code is used in}} % cross-reference for uses of sections
  114. \let\V=\lor % logical or
  115. \let\W=\land % logical and
  116. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  117.   \XX$\langle\,$#2{\eightrm\kern.5em#1}$\,\rangle$\XX}
  118. \def\Y{\par\yskip}
  119. \let\Z=\let % now you can \send the control sequence \Z
  120. \def\]{\hbox{\.{@\\}}} % sign for forced line break
  121. \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
  122.         \hbox{\strut\kern2pt\.{#1}\kern2pt}}
  123.       \hrule}\vrule}\kern2pt} % verbatim string
  124. \let\*=*
  125.  
  126. \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
  127. \newif\ifon \newif\iftitle \newif\ifpagesaved
  128. \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad
  129.   \tensy x\mainfont\topmark} % top line on left-hand pages
  130. \def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead
  131.   \qquad\mainfont\the\pageno} % top line on right-hand pages
  132. \def\page{\box255 }
  133. \def\normaloutput#1#2#3{\shipout\vbox{
  134.   \ifodd\pageno\hoffset=\pageshift\fi
  135.   \vbox to\fullpageheight{
  136.   \iftitle\global\titlefalse
  137.   \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
  138.   \vfill#1}} % parameter #1 is the page itself
  139.   \global\advance\pageno by1}
  140.  
  141. \def\rhead{\.{WEB} OUTPUT} % this running head is reset by starred sections
  142. \def\title{} % an optional title can be set by the user
  143. \def\topofcontents{\centerline{\titlefont\title}
  144.   \vfill} % this material will start the table of contents page
  145. \def\botofcontents{\vfill} % this material will end the table of contents page
  146. \def\contentspagenumber{0} % default page number for table of contents
  147. \newdimen\pagewidth \pagewidth=6.5in % the width of each page
  148. \newdimen\pageheight \pageheight=8.7in % the height of each page
  149. \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
  150. \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
  151. \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
  152.   \fullpageheight=9truein\setpage}
  153. \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
  154. \def\contentsfile{\jobname.toc} % file that gets table of contents info
  155. \def\readcontents{\input \jobname.toc}
  156.  
  157. \newwrite\cont
  158. \output{\setbox0=\page % the first page is garbage
  159.   \openout\cont=\contentsfile
  160.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161.   %%%  Start of Modification by wtho 09-08-88
  162.        \write\cont{\catcode `\noexpand\@=11\relax}   % \makeatletter
  163.   %%%  End of Modification by wtho 09-08-88
  164.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  165.   \global\output{\normaloutput\page\lheader\rheader}}
  166. \setpage
  167. \vbox to \vsize{} % the first \topmark won't be null
  168.  
  169. \def\ch{\note{The following sections were changed by the change file:}
  170.   \let\*=\relax}
  171. \newbox\sbox % saved box preceding the index
  172. \newbox\lbox % lefthand column in the index
  173. \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
  174.   \write\cont{} % ensure that the contents file isn't empty
  175.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  176.   %%%  Start of Modification by wtho 09-08-88
  177.        \write\cont{\catcode `\noexpand\@=12\relax}   % \makeatother
  178.   %%%  End of Modification by wtho 09-08-88
  179.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  180.   \closeout\cont % the contents information has been fully gathered
  181.   \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
  182.     \global\setbox\sbox=\page \global\pagesavedtrue}
  183.   \pagesavedfalse \eject % eject the page-so-far and predecessors
  184.   \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
  185.   \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
  186.   \hsize=.5\pagewidth \advance\hsize by -10pt
  187.     % column width for the index (20pt between cols)
  188.   \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
  189.   \def\lr{L} % this tells whether the left or right column is next
  190.   \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
  191.     \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
  192.         \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
  193.     \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
  194.   \message{Index:}
  195.   \parskip 0pt plus .5pt
  196.   \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
  197.   \def\[##1]{$\underline{##1}$} % underlined index item
  198.   \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
  199.   \hyphenpenalty 10000 \parindent0pt}
  200. \def\fin{\par\vfill\eject % this is done when we are ending the index
  201.   \ifpagesaved\null\vfill\eject\fi % output a null index column
  202.   \if L\lr\else\null\vfill\eject\fi % finish the current page
  203.   \parfillskip 0pt plus 1fil
  204.   \def\rhead{NAMES OF THE SECTIONS}
  205.   \message{Section names:}
  206.   \output{\normaloutput\page\lheader\rheader}
  207.   \setpage
  208.   \def\note##1##2.{\quad{\eightrm##1 ##2.}}
  209.   \def\U{\note{Used in}} % cross-reference for uses of sections
  210.   \def\:{\par\hangindent 2em}\let\*=*}
  211. \def\con{\par\vfill\eject % finish the section names
  212.   \rightskip 0pt \hyphenpenalty 50 \tolerance 200
  213.   \setpage
  214.   \output{\normaloutput\page\lheader\rheader}
  215.   \titletrue % prepare to output the table of contents
  216.   \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
  217.   \message{Table of contents:}
  218.   \topofcontents
  219.   \line{\hfil Section\hbox to3em{\hss Page}}
  220.   \def\Z##1##2##3{\line{\ignorespaces##1
  221.     \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
  222.   \readcontents\relax % read the contents info
  223.   \botofcontents \end} % print the contents page(s) and terminate
  224. \tracingstats1 % temporary (during development)
  225. \def\FE{\mathrel{/=}}
  226. \def\PP{\mathord{++}}
  227. \def\PE{\mathrel{+=}}
  228. \def\MM{\mathord{--}}
  229. \def\ME{\mathrel{-=}}
  230. \def\MG{\mathrel{\to}}
  231. \def\GG{\mathrel{>\!>}}
  232. \def\LL{\mathrel{<\!<}}
  233. \def\TE{\mathrel{\ast=}}
  234. \def\CE{\mathrel{\%=}}
  235. \def\HE{\mathrel{\uparrow=}}
  236. \def\AE{\mathrel{\&=}}
  237. \def\OE{\mathrel{|=}}
  238. \let\openbraces=\{
  239. \let\closebraces=\}
  240. \def\{{\ifmmode\openbraces\else$\openbraces$\fi}
  241. \def\}{\ifmmode\closebraces\else$\closebraces$\fi}
  242.  
  243.  
  244.